<%@ page language="java" import="java.util.*,com.lab.po.Student"
	pageEncoding="utf-8"%>
<%@ page import="com.lab.dao.impl.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<title>显示课程信息</title>

     <style type="text/css">
       input[type="text"]{
              height: auto;
	          margin-top: 8px;
	          padding: 3px 9px;
            }
        a {
  			cursor:pointer;
		}
     </style>
     <script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery-1.8.3.js"></script>
     </head>
	
	


<script type="text/javascript">

	
function query(currentPage){
		
		var regExp=/\s/g;
		var cou_name=$("#cou_id").val().replace(regExp,"");
		$.ajax({
			url:"${pageContext.request.contextPath}/courseAjaxServlet",
			type:"post",
			data:{cou_name:cou_name,currentPage:currentPage},
			dataType:"json",
			success:function(result){
				$("#coursetable").html('');

				$.each(result,function(inx,ele){
					$("#coursetable").append("<tr><td align='center' width='50%'>"+ele.cou_name+"</td>"
							+"<td align='center' width='50%'>"
							+"<a onclick='det("+ele.cou_id+")' class='btn btn-danger'>删除</a>&nbsp;"
							+"<a href='preServlet?method=updateCourse&cou_id="+ele.cou_id+"' class='btn btn-primary'>更新</a></td></tr>");
					
				})
			}
		});
		$.ajax({
			url:"${pageContext.request.contextPath}/couPageAjax",
			type:"post",
			data:{cou_name:cou_name,currentPage:currentPage},
			dataType:"text",
			success:function(result){	
				$("#pagetable").html('');
				$("#pagetable").append(result);
			}
		});
}
function det(id){
	if(confirm("确定要删除吗？")) {
		location.href = "${pageContext.request.contextPath}/deleteServlet?method=deleteCourse&cou_id=" + id;
	}
}
function add(){
	location.href = "${pageContext.request.contextPath}/preServlet?method=addCourse";
	
}
function op(){
	if(confirm("确定要开启选课吗？")) {
		location.href = "${pageContext.request.contextPath}/updateServlet?method=updateStatus&status=1";
	}
}
function clo(){
	if(confirm("确定要关闭选课吗？")) {
		location.href = "${pageContext.request.contextPath}/updateServlet?method=updateStatus&status=0";
	}
}
</script>
	<body>

        <div class="container" >
        	<div align="right">选课状态：
        	<c:if test="${status==0 }">
        	<input type="radio" name="yn" onclick="op()"/>开启<input type="radio" name="yn" checked="checked"/>关闭
        	</c:if>
        	<c:if test="${status==1 }">
        	<input type="radio" name="yn"  checked="checked"/>开启<input type="radio" name="yn" onclick="clo()"/>关闭
        	</c:if>
        	</div>
        	<div align="center">
                                                 课程<input type="text" name="searchId" id="cou_id" placeholder="课程名称..."> <i class="icon-search"></i>&nbsp;
          	 	<button type="button" class="btn btn-inverse" onclick="query(1)"> 查找</button> <a onclick="add()" class="btn btn-primary">新增</a>
          	</div>
        </div>
		<table  class="table table-hover table-condensed">
		    <tr>
				<td align="center" width="50%"><strong>课程</strong></td>
				<td align="center" width="50%"><strong>执行操作</strong></td>
			</tr>
			<table class="table table-hover table-condensed" id="coursetable">
			<c:forEach items="${courseList}" var="course" varStatus="vs">
			<tr>
				<td align="center" width="50%"><c:out value="${course.cou_name}" /></td>
				<td align="center" id="delup" width="50%">
					<a onclick="det(${course.cou_id})" class="btn btn-danger">删除</a>
					<a href="preServlet?method=updateCourse&cou_id=${course.cou_id}" class="btn btn-primary">更新</a>
				</td>
			</tr>
			</c:forEach>
			</table>
			
			<table class="table table-hover table-condensed" id="pagetable">
			<tr>
			<td colspan="8">
			当前页：${PageBean.currentPage }/${PageBean.totalPage }&nbsp;
					<a href="${pageContext.request.contextPath}/showAllServlet?method=showCourse&currentPage=1">首页</a>&nbsp;
					<c:if test="${PageBean.currentPage==1 }">
						<a href="${pageContext.request.contextPath}/showAllServlet?method=showCourse&currentPage=1">上一页</a>&nbsp;
					</c:if>
					<c:if test="${PageBean.currentPage!=1 }">
						<a href="${pageContext.request.contextPath}/showAllServlet?method=showCourse&currentPage=${PageBean.currentPage-1}">上一页</a>&nbsp;
					</c:if>
					<c:if test="${PageBean.currentPage==PageBean.totalPage }">
						<a href="${pageContext.request.contextPath}/showAllServlet?method=showCourse&currentPage=${PageBean.totalPage}">下一页</a>&nbsp;
					</c:if>
					<c:if test="${PageBean.currentPage!=PageBean.totalPage  }">
						<a href="${pageContext.request.contextPath}/showAllServlet?method=showCourse&currentPage=${PageBean.currentPage+1}">下一页</a>&nbsp;
					</c:if>
					<a href="${pageContext.request.contextPath}/showAllServlet?method=showCourse&currentPage=${PageBean.totalPage}">末页</a>
			</td>
			</tr>
			</table>
		</table>	
		<hr>
		<a href="main.jsp" class="btn btn-success">返回主菜单</a>
		<hr>


	</body>
</html>
